import time

from data002.Base import Base
from selenium.webdriver.common.by import By

class Page(Base):
    # 点击登录
    click_dl_loc = (By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a')
    def click_dl(self):
        self.click(self.click_dl_loc)
    # 账号
    username_loc = (By.NAME,'username')
    def username(self):
        self.send_keys(self.username_loc,'123455556666')
    # 密码
    password_loc = (By.NAME,'password')
    def password(self):
        self.send_keys(self.password_loc,'123456')
    # 点击登录
    finish_loc = (By.CLASS_NAME,'finish-btn')
    def finish(self):
        self.click(self.finish_loc)
    # 首页
    sy_loc = (By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a')
    def sy(self):
        self.click(self.sy_loc)
    # 搜索商品
    keywords_loc = (By.XPATH,'//*[@id="searchForm"]/div[1]/input')
    def keywords(self):
        self.send_keys(self.keywords_loc,'音乐耳机')
    # 点击搜索 search-input-btn
    search_loc = (By.CLASS_NAME,'search-input-btn')
    def search(self):
        self.click(self.search_loc)
    # 点击商品 lazy
    lazy_loc = (By.CLASS_NAME,'lazy')
    def lazy(self):
        self.click(self.lazy_loc)
    # 提取商品名称 //*[@id="goodsForm"]/div/div[1]/span
    span_loc = (By.XPATH,'//*[@id="goodsForm"]/div/div[1]/span')
    def span(self):
        return self.text(self.span_loc)
    def test_a3mall_login(self):
        self.open_url('http://10.59.9.12:7001/')
        self.click_dl()
        self.username()
        self.password()
        time.sleep(7)
        self.finish()
        time.sleep(5)
        self.sy()
        time.sleep(1)
        self.keywords()
        time.sleep(1)
        self.search()
        time.sleep(1)
        self.lazy()
        time.sleep(1)
        print("商品名称:",self.span())
        time.sleep(3)
